Completed
Push — master ( 6b7b93...3c2c59 )
by Maxence
02:59
created

curr.defineCircle   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
nc 1
nop 1
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
31
/** global: nav */
32
/** global: actions */
33
/** global: elements */
34
/** global: results */
35
36
37
var api = OCA.Circles.api;
38
var curr = {
39
	circlesType: '',
40
	circle: 0,
41
	circleName: '',
42
	circleLevel: 0,
43
	circleStatus: '',
44
	searchCircle: '',
45
	searchFilter: 0,
46
	searchUser: '',
47
	allowed_federated: 0,
48
	allowed_circles: 0,
49
50
	defineCircle: function(data)
51
	{
52
		curr.circle = data.circle_id;
53
		curr.circleName = data.details.name;
54
		curr.circleSettings = data.details.settings;
55
		curr.circleLevel = data.details.user.level;
56
		curr.circleStatus = data.details.user.status;
57
	}
58
};
59
60
var define = {
61
	levelMember: 1,
62
	levelModerator: 4,
63
	levelAdmin: 8,
64
	levelOwner: 9,
65
	linkRequested: 6,
66
	linkUp: 9,
67
	animationSpeed: 100,
68
	animationMenuSpeed: 30
69
};
70
71
72
$(document).ready(function () {
73
74
	/**
75
	 * @constructs Navigation
76
	 */
77
	var Navigation = function () {
78
79
		$.extend(Navigation.prototype, curr);
80
		$.extend(Navigation.prototype, nav);
81
		$.extend(Navigation.prototype, elements);
82
		$.extend(Navigation.prototype, actions);
83
		$.extend(Navigation.prototype, settings);
0 ignored issues
show
Bug introduced by
The variable settings seems to be never declared. If this is a global, consider adding a /** global: settings */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
84
		$.extend(Navigation.prototype, resultCircles);
0 ignored issues
show
Bug introduced by
The variable resultCircles seems to be never declared. If this is a global, consider adding a /** global: resultCircles */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
85
		$.extend(Navigation.prototype, resultMembers);
0 ignored issues
show
Bug introduced by
The variable resultMembers seems to be never declared. If this is a global, consider adding a /** global: resultMembers */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
86
		$.extend(Navigation.prototype, resultLinks);
0 ignored issues
show
Bug introduced by
The variable resultLinks seems to be never declared. If this is a global, consider adding a /** global: resultLinks */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
87
88
		this.init();
89
		this.initTransifex();
90
		this.retrieveSettings();
91
	};
92
93
94
	Navigation.prototype = {
95
96
		init: function () {
97
			elements.initElements();
98
			elements.initUI();
99
			elements.initTweaks();
100
			elements.initAnimationNewCircle();
101
			elements.initExperienceCirclesList();
102
			elements.initExperienceCircleButtons();
103
			//elements.initExperienceMemberDetails();
104
			nav.initNavigation();
105
		},
106
107
		initTransifex: function () {
108
			t('circles', 'Personal Circle');
109
			t('circles', 'Hidden Circle');
110
			t('circles', 'Private Circle');
111
			t('circles', 'Public Circle');
112
113
			t('circles', 'Personal');
114
			t('circles', 'Hidden');
115
			t('circles', 'Private');
116
			t('circles', 'Public');
117
118
			t('circles', 'Not a member');
119
			t('circles', 'Member');
120
			t('circles', 'Moderator');
121
			t('circles', 'Admin');
122
			t('circles', 'Owner');
123
124
125
			t('circles', 'Unknown');
126
			t('circles', 'Invited');
127
			t('circles', 'Requesting');
128
			t('circles', 'Blocked');
129
			t('circles', 'Kicked');
130
		},
131
132
		retrieveSettings: function () {
133
			var self = this;
134
135
			$.ajax({
136
				method: 'GET',
137
				url: OC.generateUrl('/apps/circles/settings'),
138
			}).done(function (result) {
139
				self.retrieveSettingsResult(result)
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
140
			}).fail(function () {
141
				self.retrieveSettingsResult({status: -1});
142
			});
143
		},
144
145
		retrieveSettingsResult: function (result) {
146
			if (result.status !== 1) {
147
				return;
148
			}
149
150
			curr.allowed_federated = result.allowed_federated;
151
			curr.allowed_circles = result.allowed_circles;
152
153
			var circleId = window.location.hash.substr(1);
154
			if (circleId) {
155
				actions.selectCircle(circleId);
156
			}
157
		}
158
159
	};
160
161
162
	/**
163
	 * @constructs Notification
164
	 */
165
	var Notification = function () {
166
		this.initialize();
167
	};
168
169
	Notification.prototype = {
170
171
		initialize: function () {
172
173
			//noinspection SpellCheckingInspection
174
			var notyf = new Notyf({
175
				delay: 5000
176
			});
177
178
			this.onSuccess = function (text) {
179
				notyf.confirm(text);
180
			};
181
182
			this.onFail = function (text) {
183
				notyf.alert(text);
184
			};
185
186
		}
187
188
	};
189
190
	OCA.Circles.Navigation = Navigation;
191
	OCA.Circles.navigation = new Navigation();
192
193
	OCA.Notification = Notification;
194
	OCA.notification = new Notification();
195
196
});
197
198